import http, { ApiResponse } from '../utils/request';

// 文章列表接口
export interface Articles {
  rows: any[];
  total: number;
}

// 分类列表接口
export interface Categories {
  rows: any[];
  total: number;
}

// 文章查询参数接口
export interface ArticleParams {
  id?: number | string;
  categoryId?: number | string;
  page?: number;
  pageSize?: number;
  [key: string]: any;
}

/**
 * 获取文章列表
 * @param params 查询参数
 * @returns Promise
 */
export const getArticles = (params: ArticleParams): Promise<ApiResponse<Articles>> => {
  return http.get<Articles>('/articles', params);
};

/**
 * 创建文章
 * @param data 文章数据
 * @returns Promise
 */
export const createArticle = (data: any): Promise<ApiResponse<any>> => {
  return http.post<any>('/articles', data);
};

/**
 * 更新文章
 * @param article 文章数据
 * @returns Promise
 */
export const updateArticle = (article: any): Promise<ApiResponse<any>> => {
  return http.put<any>(`/articles/${article.id}`, article);
};

/**
 * 删除文章
 * @param id 文章ID
 * @returns Promise
 */
export const deleteArticle = (id: string | number): Promise<ApiResponse<any>> => {
  return http.delete<any>(`/articles/${id}`);
};

/**
 * 获取分类
 * @returns Promise
 */
export const getCategories = (): Promise<ApiResponse<Categories>> => {
  return http.get<Categories>('/categories');
};